<?php

/**
 * This is the model class for table "order".
 *
 * The followings are the available columns in table 'order':
 * @property integer $order_id
 * @property integer $customer_id
 * @property integer $user_id
 * @property string $description
 * @property integer $created_time
 * @property integer $last_updated_time
 *
 * The followings are the available model relations:
 * @property OrderDetail[] $orderDetail
 */
class Order extends CActiveRecord
{

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Order the static model class
     */
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'order';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('user_id, created_time, last_updated_time', 'numerical', 'integerOnly' => true),
            array('user_id, created_time, last_updated_time', 'length', 'max' => 10),
            array('description', 'length', 'max' => 1000),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('order_id, customer_id, user_id, description, created_time, last_updated_time', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'orderDetail' => array(self::HAS_MANY, 'OrderDetail', 'order_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'order_id' 			=> '#',
            'customer_id' 		=> 'Khác hàng',
            'user_id' 			=> 'Nhân viên bán hàng',
            'description' 		=> 'Ghi chú',
            'created_time' 		=> 'Ngày bán',
            'last_updated_time'	=> 'Lần cập nhật gần nhất'
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('order_id', $this->order_id, true);
        $criteria->compare('customer_id', $this->customer_id, true);
        $criteria->compare('user_id', $this->user_id, true);
		$criteria->compare('description', $this->description, true);
		$criteria->compare('created_time', $this->created_time, true);
		$criteria->compare('last_updated_time', $this->created_time, true);
        

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }
}
